﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Controller;

namespace WebCrawler
{
    public partial class Form1 : Form
    {
        private CrawlerCtr crawlerCtr;
        private TreeCtr treeCtr;
        public Form1()
        {
            InitializeComponent();
            crawlerCtr = new CrawlerCtr();
            
        }

        private void givGasButton_Click(object sender, EventArgs e)
        {
            treeView1.Nodes.Clear();
            crawlerCtr.ClearConsole();
            crawlerCtr.ClearGraph();
            crawlerCtr.ClearNewUrl();
            
            
            webBrowser1.Navigate(linkTxt.Text);
            crawlerCtr.StartCrawl(linkTxt.Text, (int)numericUpDown1.Value);
            crawlerCtr.PrintVerticesInGraph();
            MakeTreeView();

            
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
                
        }
        private void MakeTreeView()
        {
            Console.WriteLine("TreeDebugStart ");
            treeView1.Nodes.Clear();
            treeCtr = TreeCtr.GetInstance(linkTxt.Text);
            TreeNode rootNode = treeView1.Nodes.Add(linkTxt.Text);

            List<TreeNode> tnList = treeCtr.GetAllTreeNodes();
            Console.WriteLine("TreeDebug: " + tnList.Count);
            TreeNode[] tna = new TreeNode[tnList.Count];
            int listCounter = 0;

                foreach(TreeNode t in tnList)
                {
                    Console.WriteLine("TreeDebug: " + t.Text);
                    if(listCounter <= tnList.Count)
                    {
                        tna[listCounter] = t;
                        listCounter++;
                        
                    }
               }
            treeView1.Nodes.AddRange(tna);
            }
            
        }
    }

